package com.mycompany.oj.controller;

import com.mycompany.oj.aspect.JudgeLog;
import com.mycompany.oj.entity.JsonResult;
import com.mycompany.oj.entity.ProjectSituation;
import com.mycompany.oj.entity.ResultCode;
import com.mycompany.oj.service.Impl.TeacherServiceImpl;
import com.mycompany.oj.util.SharedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *
 * @author asus
 */
@RestController
public class TeacherController {

    @Autowired
    TeacherServiceImpl teacherservice;

    private SharedService sharedService = new SharedService();

    //获取管理员头像
    @JudgeLog
    @RequestMapping("/get_admin_picture")
    public JsonResult doGetAdminPicture(HttpServletRequest request) throws Exception {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.getAdminPicure(sharedService.getUsername(request)));
    }

    //获取管理员名字
    @JudgeLog
    @RequestMapping("/get_admin_name")
    public JsonResult doGetAdminName(HttpServletRequest request) throws Exception {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.getAdminName(sharedService.getUsername(request)));
    }

    //获取每日的提交量
    @JudgeLog
    @RequestMapping("/get_everydaypost_number")
    public JsonResult doGetEverydayPost() {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.getEverydayPostNumberService());
    }

    //获取注册用户个数，竞赛题库数目，实验题库数目
    @JudgeLog
    @RequestMapping("/get_three_number")
    public JsonResult doGetThreeNumber() {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.getNumber());
    }

    //获取所有学生的信息
    @JudgeLog
    @RequestMapping("/get_all_student_information")
    public JsonResult doGetAllStudentInformation(@RequestParam("grade") String grade) {

        return new JsonResult(ResultCode.SUCCESS, teacherservice.getAllStudentInformation(grade));
    }

    //实验题库总情况
    @JudgeLog
    @RequestMapping("/get_section_information")
    public JsonResult doGetSectionInformation() {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.getSectionInformation());
    }

    //修改实验题目
    @JudgeLog
    @RequestMapping("/change_course_question")
    public JsonResult doChangeCourseQuestion(HttpServletRequest request) {
        String question_id = request.getParameter("question_id");
        String question_text = request.getParameter("question_text");
        String question_name = request.getParameter("question_name");
        teacherservice.doChangeQuestion(question_name, question_text, question_id);
        return new JsonResult(ResultCode.SUCCESS);
    }

    //课程总结
    @JudgeLog
    @RequestMapping("/course_summary")
    public JsonResult doCourseSummary(@RequestParam("coursename") String coursename) {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.courseSummarize(coursename));
    }

    //题目完成人数
    @JudgeLog
    @RequestMapping("/question_finished_num")
    public JsonResult doQuestionFinishedNum(@RequestParam("coursename") String coursename) {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.addCourseInformation(coursename));
    }

    //删除题目
    @JudgeLog
    @RequestMapping("/delete_answer")
    public JsonResult doDelete(@RequestParam("question_id") String question_id) {

        return teacherservice.deleteQuestion(question_id);
    }

    //获取各个题库题目数量
    @JudgeLog
    @RequestMapping("/question_number")
    public JsonResult doQuestionNumber() {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.questionNumber());
    }

    //实验管理
    @RequestMapping("/All_Course")
    public JsonResult getAllCourse() {
        return new JsonResult(ResultCode.SUCCESS, teacherservice.getAllCourse());
    }
    
    //获取停用课程
    @RequestMapping("/All_stop_Course")
    public JsonResult getAllStopCourse(){
        return new JsonResult(ResultCode.SUCCESS,teacherservice.getStopCourse());
    }
    //获取停用章节
    @RequestMapping("/All_stop_Section")
    public JsonResult getAllStopSection(){
        return new JsonResult(ResultCode.SUCCESS,teacherservice.getStopSection());
    }
    //获取停用问题
    @RequestMapping("/All_stop_Question")
    public JsonResult getAllStopQuestion(){
        return new JsonResult(ResultCode.SUCCESS,teacherservice.getStopQuestion());
    }

    //上传实验题目
    @JudgeLog
    @RequestMapping("/Importquestion")
    public void doImportquestion(@RequestParam("file") MultipartFile file) throws Exception {

    }

    //上传竞赛题目
    @RequestMapping("/ImportCoursequestion")
    public void doImportCoursequestion(@RequestParam("file") MultipartFile file) throws Exception {

    }

    @RequestMapping("/project_situation")
    public List<ProjectSituation> doProjectSituation(@RequestParam("coursename") String coursename) {
        return teacherservice.prjectSituation(coursename);
    }

    //获取网站情况
    @RequestMapping("/web_situation")
    public JsonResult doWebSituation() {
        return teacherservice.doWebService();
    }

    //题库管理
    @RequestMapping("/gurantee")
    public JsonResult doGuarantee(@RequestParam("kind") String kind) {
        return teacherservice.doGuranteeService(kind);
    }

    //各个实验的详细信息
    @RequestMapping("/gurantee_course")
    public JsonResult doGuranteeCourse(@RequestParam("coursename") String coursename) {
        return teacherservice.getCourseStudent(coursename);
    }

    //删除课程
    @RequestMapping("/delete_course")
    public JsonResult doDeleteCourse(@RequestParam("coursename") String coursename){
        return teacherservice.deleteCourse(coursename);
    }
    
    //查询
    @RequestMapping("/search")
    public JsonResult doSearch(@RequestParam("grade") String grade, @RequestParam("name") String name, @RequestParam("schoolid") String schoolid){
        return teacherservice.doSearchStudent(grade, name, schoolid);
    }
    
    //停用课程
    @RequestMapping("/stop_course")
    public JsonResult doStopCourse(@RequestParam("course") String course){
        return teacherservice.stopCourse(course);
    }
    
    //停用章节
    @RequestMapping("/stop_section")
    public JsonResult do_stop_section(@RequestParam("course") String course,@RequestParam String section_num){
        return teacherservice.stopSection(course,section_num);
    }
    
    
    //停用问题
    @RequestMapping("/stop_question")
    public JsonResult doStopQuestion(@RequestParam("question_id") String question_id){
        return teacherservice.stopQuestion(question_id);
    }
    
    
    //启用课程
    @RequestMapping("/start_course")
    public JsonResult doStartCourse(@RequestParam("course") String course){
        return teacherservice.startCourse(course);
    }
    
    //启用章节
    @RequestMapping("/start_section")
    public JsonResult doStartSection(@RequestParam("course") String course, @RequestParam String section_num){
        return teacherservice.startSection(course,section_num);
    }
    
    
    //启用问题
    @RequestMapping("/start_question")
    public JsonResult doStartQuestion(@RequestParam("question_id") String question_id){
        return teacherservice.startQuestion(question_id);
    }
    
    //修改章节信息
    @RequestMapping("/change_Section_Information")
    public JsonResult doChangeSectionInformation(@RequestParam("course_name") String course_name, @RequestParam("question_course_id") String question_course_id, @RequestParam("name") String name, @RequestParam("end_data") String end_data, @RequestParam("gogal") String gogal){
        return teacherservice.changeCourseQuestion(course_name,question_course_id, name, gogal, end_data);
    }
    
    //删除用户
    @RequestMapping("/delete_student")
    public JsonResult doDeleteStudent(@RequestParam("student_id") String student_id){
        return teacherservice.deleteStudent(student_id);
    }
    
    //添加章节
    @RequestMapping("/Add_Section")
    public JsonResult doAddSection(@RequestParam("course_name") String course_name, @RequestParam("section_name") String section_name, @RequestParam("section_num") String section_num, @RequestParam("section_gogal") String section_gogal, @RequestParam("section_end_data") String section_end_data){
        return teacherservice.addSection(course_name,section_name,section_num,section_gogal,section_gogal);
    }
    
    //添加题目
    @RequestMapping("/Add_Question")
    public JsonResult doAddQuestion(@RequestParam("course_name") String course_name, @RequestParam("section_num") String section_num, @RequestParam("question_name") String question_name, @RequestParam("question_text") String question_text, @RequestParam("file") MultipartFile[] file, @RequestParam("answer") String answer){
        return teacherservice.addQuestion(course_name, section_num, question_name, question_text, file, answer);
    }
}
